package com.bootdo.staticmask.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.staticmask.domain.MaskEncodeDO;
import com.bootdo.staticmask.service.MaskEncodeService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 编码种类
 * 
 * @author lkg
 * @email lkggod@163.com
 * @date 2018-04-25 11:27:34
 */
 
//@Controller
//@RequestMapping("/staticmask/maskEncode")
public class MaskEncodeController {

	private final MaskEncodeService maskEncodeService;

	@Autowired
	public MaskEncodeController(MaskEncodeService maskEncodeService) {
		this.maskEncodeService = maskEncodeService;
	}


	@GetMapping()
	//@RequiresPermissions("staticmask:maskEncode:maskEncode")
	String MaskEncode(){
	    return "staticmask/maskEncode/maskEncode";
	}

	@ResponseBody
	@GetMapping("/findAll")
	public List<MaskEncodeDO> findAll(){
		return maskEncodeService.findAll();
	}

	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("staticmask:maskEncode:maskEncode")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<MaskEncodeDO> maskEncodeList = maskEncodeService.list(query);
		int total = maskEncodeService.count(query);
		PageUtils pageUtils = new PageUtils(maskEncodeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("staticmask:maskEncode:add")
	String add(){
	    return "staticmask/maskEncode/add";
	}

	@GetMapping("/edit/{encodeId}")
	@RequiresPermissions("staticmask:maskEncode:edit")
	String edit(@PathVariable("encodeId") Integer encodeId,Model model){
		MaskEncodeDO maskEncode = maskEncodeService.get(encodeId);
		model.addAttribute("maskEncode", maskEncode);
	    return "staticmask/maskEncode/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("staticmask:maskEncode:add")
	public R save( MaskEncodeDO maskEncode){
		if(maskEncodeService.save(maskEncode)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("staticmask:maskEncode:edit")
	public R update( MaskEncodeDO maskEncode){
		maskEncodeService.update(maskEncode);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("staticmask:maskEncode:remove")
	public R remove( Integer encodeId){
		if(maskEncodeService.remove(encodeId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("staticmask:maskEncode:remove")
	public R remove(@RequestParam("ids[]") Integer[] encodeIds){
		maskEncodeService.batchRemove(encodeIds);
		return R.ok();
	}
	
}
